Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

P1 345 woo shopping data in google preview #1118

Merged
merged 25 commits into from
Apr 12, 2021

Conversation

marijnyoast
Copy link
Contributor

Summary

This PR can be summarized in the following changelog entry:

  • [@yoast/search-metadata-previews] When product data like rating, number of reviews, price or availability is provided, it is now shown in the Google Preview.

Relevant technical choices:

Test instructions

This PR can be tested by following these steps:

  • Please follow the test instructions in the corresponding branch / version of WP SEO for WooCommerce

Impact check

  • This PR affects the following parts of the plugin, which may require extra testing:
    • Search metadata preview

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Quality assurance

  • I have tested this code to the best of my abilities
  • I have added unittests to verify the code works as intended

Fixes P1-345

@marijnyoast marijnyoast added innovation changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog labels Mar 24, 2021
@marijnyoast marijnyoast added this to the 16.2 milestone Mar 24, 2021
Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 🏗️

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 🏗️

Comment on lines 735 to 753
if ( shoppingData !== {} ) {

if ( mode === MODE_DESKTOP ) {
return (
<ProductDataDesktop
shoppingData={ shoppingData }
/>
);
}

if ( mode === MODE_MOBILE ) {
return (
<ProductDataMobile
shoppingData={ shoppingData }
/>
);
}

return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things:

  • You can not compare an object to an empty different object. It compares the memory address and thus will never be the same. You can work around this by checking if there are any values for example.
  • You can early return on the shoppingData check so you don't have to indent for all the rest. This improves readability of your code.
  • You are missing a return for when the shoppingData is empty, that will be undefined instead of null in your current code. That is not a problem in behavior, but it is not correct.
Suggested change
if ( shoppingData !== {} ) {
if ( mode === MODE_DESKTOP ) {
return (
<ProductDataDesktop
shoppingData={ shoppingData }
/>
);
}
if ( mode === MODE_MOBILE ) {
return (
<ProductDataMobile
shoppingData={ shoppingData }
/>
);
}
return null;
if ( Object.values( shoppingData ).length === 0 ) {
return null;
}
if ( mode === MODE_DESKTOP ) {
return (
<ProductDataDesktop
shoppingData={ shoppingData }
/>
);
}
if ( mode === MODE_MOBILE ) {
return (
<ProductDataMobile
shoppingData={ shoppingData }
/>
);
}
return null;

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 👍

@JoseeWouters
Copy link
Contributor

Acceptance 👍

@JoseeWouters JoseeWouters merged commit 2d242c7 into develop Apr 12, 2021
@JoseeWouters JoseeWouters deleted the P1-345-Woo-shopping-data-in-google-preview branch April 12, 2021 08:35
@marijnyoast marijnyoast modified the milestones: 16.2, 16.3 Apr 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog innovation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants